package com.hunray.rent.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
@Entity
@Table(name="t_rent")
public class Rent implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Integer id;
	
	private String no;
	
	private User creater;
	
	private Date createDate;
	
	private ChargeMode chargeMode;//计价方式，如按天、按月等
	
	private User renter;
	
	private Back back;
	
	private Income income;
	
	private List<DeviceRent> deviceRents;
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "tg_rent")
	@TableGenerator(name = "tg_rent", table = "t_id", pkColumnName = "f_table", pkColumnValue = "t_rent", valueColumnName = "f_id", allocationSize = 1, initialValue = 1)
	@Column(name = "f_id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name="f_no",nullable=false,unique=true)
	@NotNull
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}
	@Column(name="f_creater")
	public User getCreater() {
		return creater;
	}

	public void setCreater(User creater) {
		this.creater = creater;
	}
	@Temporal(TemporalType.DATE)
	@Column(name="f_create_date")
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name="f_charge_mode")
	public ChargeMode getChargeMode() {
		return chargeMode;
	}

	public void setChargeMode(ChargeMode chargeMode) {
		this.chargeMode = chargeMode;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="f_renter")
	public User getRenter() {
		return renter;
	}
	
	public void setRenter(User renter) {
		this.renter = renter;
	}
	
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="f_back")
	public Back getBack() {
		return back;
	}

	public void setBack(Back back) {
		this.back = back;
	}
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="f_income")
	public Income getIncome() {
		return income;
	}

	public void setIncome(Income income) {
		this.income = income;
	}
	@OneToMany(fetch=FetchType.LAZY,mappedBy="rent")
	public List<DeviceRent> getDeviceRents() {
		return deviceRents;
	}

	public void setDeviceRents(List<DeviceRent> deviceRents) {
		this.deviceRents = deviceRents;
	}
	
	

}
